package com.example.waibao.handler;//package com.example.sannong.handler;
//
//import cn.hutool.json.JSONUtil;
//import com.example.sannong.entity.Result;
//import com.example.sannong.utils.Jwtutils;
//
//import org.springframework.security.core.Authentication;
//import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
//import org.springframework.stereotype.Component;
//
//
//import javax.servlet.http.HttpServletRequest;
//import java.io.IOException;
//
//
//@Component
//public class LoginSuccessHandler implements AuthenticationSuccessHandler {
//
//    @Override
//    public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException {
//
//        response.setContentType("application/json;charset=UTF-8");
//        ServletOutputStream outputStream = response.getOutputStream();
//
//        int id = 2;
//        String username = "admin";
//        String token = Jwtutils.createToken(id, username);
//
//
//        outputStream.write(JSONUtil.toJsonStr(Result.success("登录成功").put("admin",token)).getBytes());
//        outputStream.flush();
//        outputStream.close();
//    }
//}
